<?php
class collection_collect_index extends collection_collect_abstract {
		
	public function Collect() {
		$response = $this->getResponse();
		if(!($eItem = $this->get('exp_item'))) {
			throw new collection_exception("Regular Expression of Item Matched is Empty.");
		}
		$eArea = $this->get('exp_area');
		$mTitle = intval($this->get('matched_title', '2'));
		$mLink = intval($this->get('matched_link', '1'));
		try {
			$_area = $response;
			if($eArea && preg_match("#$eArea#isU", $response, $area)) {
				$_area = $area[1];
			}
			if(!preg_match_all("#$eItem#isU", $_area, $items)) {
				throw new collection_exception("Item can not Matched.");
			}
			$list = array();
			foreach($items[0] AS $key => $v) {
				$link = isset($items[$mLink]) ? $this->setFullLink($items[$mLink][$key]) : '';
				$title = isset($items[$mTitle]) ? trim($items[$mTitle][$key]) : '';
				$_key = system_encrypt::shortUrl($link);
				$list[$_key] = array('key' => $_key, 'title' => $title, 'url' => $link);
			}
			return $list;
		} catch (Exception $ex) {
			throw $ex;
		}
	}
	
}
